
function preUpdate(obj) {
	$(obj).hide();
	$(obj).next("input").show();
	$(obj).next("input").focus();
}

function update(obj) {
	// inspectionUpdateTestingClass

	var param = {
		id : $(obj).attr("dataid")
	};

	if ($(obj).attr("id") == "updateDisease") {
		param.disease = $(obj).val();
	}

	if ($(obj).attr("id") == "updateOriginalName") {
		param.originalName = $(obj).val();
	}
	if ($(obj).attr("id") == "updateThumbnailName") {
		param.thumbnailName = $(obj).val();
	}
	if ($(obj).attr("id") == "updateRank") {
		param.rank = $(obj).val();
		var regexp = /^[1-9]\d*$/;
	    if ( !( regexp.test($(obj).val() ) ) ) {
	    	alert("rank必须为数字");
	    	return;
	    }
	}

	API.diseaseImageUpdate(param, function(res) {
		UTIL.releaseButton(obj);
		if (res.code == '0') {
			window.location.reload();
		} else {
			alert(res.desc);
			window.location.reload();
		}
	});
}

function upload(url, name,  rank,  image, obj) {
    var formData = new FormData(document.forms.namedItem("#uploadForm"));  
    var image1 = document.getElementById("image1").files;
    var image2 = document.getElementById("image2").files;

    formData.append("image1",image1[0]);
    formData.append("image2",image2[0]);
    formData.append("name",name);
    formData.append("rank",rank);

	$.ajax({
		url : url,
        type : 'post',
        data : formData,
        cache : false,
        processData : false, // 不处理发送的数据，因为data值是Formdata对象，不需要对数据做处理
        contentType : false,
		success : function(res) {
			if (res.code == '0') {
				$(obj).dialog("close");
				window.location.href = "/icd/disease_image_list.htm?tabid=25_13";
			} else {
				alert(res.desc);
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			if ($("#errorRequestStatus")) {
				$("#errorRequestStatus").val(XMLHttpRequest.status);
			}
			if ($("#errorRequestReadyState")) {
				$("#errorRequestReadyState").val(XMLHttpRequest.readyState);
			}
			if ($("#errorTextStatus")) {
				$("#errorTextStatus").val(textStatus);
			}
			// 如果在一个方法调用未结束直接切换页面会包状态为0的错误，屏蔽掉
			if (XMLHttpRequest.status != 0) {
				alert('系统异常，请与管理员联系');
			}
		},
		complete : function() {
		}
	});
}


function batchAddClass() {
	$("#batchFile").click();
}

$("#batchFile").change(doBatchAdd);

function doBatchAdd() {
	var batchFile = $("#batchFile").val();
	var flag = "(.zip|.ZIP)$";
	 var re=new RegExp(flag);
	if (re.test(batchFile)) {
		$.ajaxFileUpload({
					url : "/icd/batch_insert_disease_image.do",
					secureuri : false,
					fileElementId : 'batchFile',
					dataType : 'json',
					data : {},
					success : function(res) {
						if (res.code == '0') {
							alert(res.desc);
							window.location.href = "/icd/disease_image_list.htm?tabid=25_13";
						} else {
							alert(res.desc);
						}
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						if ($("#errorRequestStatus")) {
							$("#errorRequestStatus").val(XMLHttpRequest.status);
						}
						if ($("#errorRequestReadyState")) {
							$("#errorRequestReadyState").val(
									XMLHttpRequest.readyState);
						}
						if ($("#errorTextStatus")) {
							$("#errorTextStatus").val(textStatus);
						}
						// 如果在一个方法调用未结束直接切换页面会包状态为0的错误，屏蔽掉
						if (XMLHttpRequest.status != 0) {
							alert('系统异常，请与管理员联系');
						}
					},
					complete : function() {
					}
				});
	} else {
		window.location.href = "/icd/disease_image_list.htm?tabid=25_13";
		alert("文件格式必须为zip。");
	}
}


var typeFlag = 0 
function updateImage(id,type) {
	$("#id").val(id);
	$("#file").click();
	typeFlag = type;
}

$("#file").change(fileChange);

function fileChange() {
	var file = $("#file").val();
	var id = $("#id").val();
	if (/.*\.[png,PNG]/.test(file)) {
		$
				.ajaxFileUpload({
					url : "/icd/update_disease_image.do",
					secureuri : false,
					fileElementId : 'file',
					dataType : 'json',
					data : {
						"id" : id,
						"type":typeFlag
					},
					success : function(res) {
						if (res.code == '0') {
							window.location.href = "/icd/disease_image_list.htm?tabid=25_13";
						} else {
							alert(res.desc);
							window.location.href = "/icd/disease_image_list.htm?tabid=25_13";
						}
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
						if ($("#errorRequestStatus")) {
							$("#errorRequestStatus").val(XMLHttpRequest.status);
						}
						if ($("#errorRequestReadyState")) {
							$("#errorRequestReadyState").val(
									XMLHttpRequest.readyState);
						}
						if ($("#errorTextStatus")) {
							$("#errorTextStatus").val(textStatus);
						}
						// 如果在一个方法调用未结束直接切换页面会包状态为0的错误，屏蔽掉
						if (XMLHttpRequest.status != 0) {
							alert('系统异常，请与管理员联系');
						}
					},
					complete : function() {
					}
				});
	} else {
		alert("图片格式必须为PNG。");
	}
}



function move(id, flag) {
	var data = {
		"id" : id,
		"flag" : flag
	};
	API.moveTestingClass(data, function(res) {
		if (res.code == 0) {
			window.location.reload();
		} else {
			alert(res.desc);
		}
	});
}
